//
//  PatientService.m
//  Nurse
//
//  Created by 夏 申频 on 14-1-5.
//  Copyright (c) 2014年 Honeywell. All rights reserved.
//

#import "PatientService.h"

//NSString* const PRODUCEBEDSFORBQ = @"DY_OUT_ZY_BRXX_XY_BQ";
 NSString* const PRODUCEBEDSFORBQ = @"DY_OUT_ZY_BRXX_XY_BQ";



@interface PatientService()
@property (nonatomic,strong) NSURL* url;
@end



@implementation PatientService

-(PatientService*)init{
    self= [super init];
    if (self) {
        self.url = [[DataEngine sharedInstance]urlForPath:@"/his/procedure"];
    }
    return self;
}

+(PatientService*) sharedInstance{
    static dispatch_once_t pred = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&pred, ^{
        _sharedObject = [[PatientService alloc] init];
    });
    return _sharedObject;
}

-(void)queryPatientsForWardCode:(NSString*)wardCode withSuccessHandler:(SuccessHandler)successHandler andFailHandler:(FailHandler)failHandler{
    ProcedureCallRequest* request = [[ProcedureCallRequest alloc]init];
    request.procedureName=PRODUCEBEDSFORBQ;
    request.params = @{@"bq":wardCode};
    request.successHandle = successHandler;
    request.failHandle = failHandler;
    [[DataEngine sharedInstance]callProcedure:request forURL:self.url];
}

-(void)queryPatientsForPID:(NSString*)pid withSuccessHandler:(SuccessHandler)successHandler andFailHandler:(FailHandler)failHandler{
    ProcedureCallRequest* request = [[ProcedureCallRequest alloc]init];
    request.procedureName=PRODUCEBEDSFORBQ;
    request.params = @{@"zyh":pid};
    request.successHandle = successHandler;
    request.failHandle = failHandler;
    [[DataEngine sharedInstance]callProcedure:request forURL:self.url];
}

-(NSDictionary*)findPatientByPID:(NSString*)pid{
    NSDictionary* result = nil;
    for (NSDictionary* patient in self.patientDicts) {
        NSString* zyh = [patient valueForKey:@"住院号"];
        if ([zyh isEqualToString:pid]) {
            result = patient;
            break;
        }
    }
    return  result;
}
@end
